package view.controller;

import common.Communication;
import common.Group;
import common.Message;
import common.NowUser;
import javafx.event.ActionEvent;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.stage.Stage;
import server.ClientConnServer;
import tools.GetTime;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.concurrent.BrokenBarrierException;

public class GroupemoController implements Initializable {
    public Label groupid;
    public Button h0;
    public Button h1;
    public Button h2;
    public Button h3;
    public Button h4;
    public Button h5;
    public Button h6;
    public Button h7;
    public Button h8;
    public Button h9;
    public Button h10;
    public Button h11;
    public Button h12;
    public Button h13;
    public Button h14;
    public Button h15;
    public Button h16;
    public Button h17;
    public Button h18;
    public Button h19;
    public Button h20;
    public Button h21;
    public Button h22;
    public Button h23;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        groupid.setText(NowUser.group.getGroupid());
    }

    public void on0(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h0.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h0.getScene().getWindow();
        stage.close();
    }

    public void on1(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h1.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h1.getScene().getWindow();
        stage.close();
    }

    public void on2(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h2.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h2.getScene().getWindow();
        stage.close();
    }

    public void on3(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h3.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h3.getScene().getWindow();
        stage.close();
    }

    public void on4(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h4.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h4.getScene().getWindow();
        stage.close();
    }

    public void on5(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h5.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h5.getScene().getWindow();
        stage.close();
    }

    public void on6(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h6.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h6.getScene().getWindow();
        stage.close();
    }

    public void on7(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h7.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h7.getScene().getWindow();
        stage.close();
    }

    public void on8(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h8.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h8.getScene().getWindow();
        stage.close();
    }

    public void on9(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h9.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h9.getScene().getWindow();
        stage.close();
    }

    public void on10(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h10.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h10.getScene().getWindow();
        stage.close();
    }

    public void on11(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h11.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h11.getScene().getWindow();
        stage.close();
    }

    public void on12(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h12.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h12.getScene().getWindow();
        stage.close();
    }

    public void on13(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h13.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h13.getScene().getWindow();
        stage.close();
    }

    public void on14(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h14.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h14.getScene().getWindow();
        stage.close();
    }

    public void on15(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h15.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h15.getScene().getWindow();
        stage.close();
    }

    public void on16(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h16.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h16.getScene().getWindow();
        stage.close();
    }

    public void on17(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h17.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h17.getScene().getWindow();
        stage.close();
    }

    public void on18(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h18.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h18.getScene().getWindow();
        stage.close();
    }

    public void on19(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h19.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h19.getScene().getWindow();
        stage.close();
    }

    public void on20(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h20.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h20.getScene().getWindow();
        stage.close();
    }

    public void on21(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h21.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h21.getScene().getWindow();
        stage.close();
    }

    public void on22(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h22.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h22.getScene().getWindow();
        stage.close();
    }

    public void on23(ActionEvent actionEvent) throws IOException, BrokenBarrierException, InterruptedException {
        Message msg = new Message();
        Communication comm  = new Communication();
        comm.setSender(NowUser.user);
        Group group=new Group();
        group.setGroupid(groupid.getText());
        group=NowUser.group;
        comm.setGroup(group);
        comm.setSender(NowUser.user);
        comm.setContent(h23.getText());
        comm.setSendDateTime(new GetTime().getTime());
        comm.setType(4);
        msg.setType("groupemoji");
        msg.setCommunication(comm);
        new ClientConnServer().sendinfo(msg);
        NowUser.cyclicBarrier.reset();
        NowUser.cyclicBarrier.await();
        Stage stage = (Stage) h23.getScene().getWindow();
        stage.close();
    }
}
